$(function() {


    var folder_url_img = 'mediagallery/img/';
    var folder_url_vid = 'mediagallery/videos/';

    var uploaderimg = new plupload.Uploader({        
        runtimes: 'flash',
        flash_swf_url: base_url+'assets/js/_plugins/plupload/plupload.flash.swf',
        browse_button: 'pickfilesimg',
        container: 'uploaderimg',
        url: base_url+'assets/js/_plugins/plupload/upload.php',
        multipart : true,
        multipart_params: { 'datafield': folder_url_img }        
    });

    uploaderimg.init();

    uploaderimg.bind('FilesAdded', function(up, files) {        
        // loop through the files array
        for (var i in files) {            
            document.getElementById('filelistimg').innerHTML += '<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <b></b></div>';            
        }
    });

    uploaderimg.bind('UploadProgress', function(up, file) {        
        document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";        
    });

    uploaderimg.bind('Error', function(up, args) {        
        alert(args.code + ': ' + args.message);        
    });

    document.getElementById('uploadfilesimg').onclick = function() {         
        uploaderimg.start();         
    }; 
    
    var uploadervid = new plupload.Uploader({        
        runtimes: 'flash',
        flash_swf_url: base_url+'assets/js/_plugins/plupload/plupload.flash.swf',
        browse_button: 'pickfilesvid',
        container: 'uploadervid',
        url: base_url+'assets/js/_plugins/plupload/upload.php',
        multipart : true,
        multipart_params: { 'datafield': folder_url_vid }        
    });

    uploadervid.init();

    uploadervid.bind('FilesAdded', function(up, files) {        
        // loop through the files array
        for (var i in files) {            
            document.getElementById('filelistvid').innerHTML += '<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <b></b></div>';            
        }
    });

    uploadervid.bind('UploadProgress', function(up, file) {        
        document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";        
    });

    uploadervid.bind('Error', function(up, args) {        
        alert(args.code + ': ' + args.message);        
    });

    document.getElementById('uploadfilesvid').onclick = function() {         
        uploadervid.start();         
    }; 


});